package igiant.customer.provider.controller;

import igiant.customer.facade.entity.Customer;
import igiant.customer.facade.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Title: CustomerController
 * @Package: igiant.customer.provider.controller
 * @Description: 用户控制，对外开放API
 * @Author: zrd <zwd_1222@126.com>
 * @date: 2016/10/12
 * @Version: V1.0
 */
@RestController
public class CustomerController {
    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private CustomerService customerService;

    /**
     * 注：@GetMapping("/{id}")是spring 4.3的新注解等价于：
     * @RequestMapping(value = "/id", method = RequestMethod.GET)
     * 类似的注解还有@PostMapping等等
     * @param id
     * @return customer信息
     */
    @GetMapping("/{id}")
    public Customer findById(@PathVariable String id) {
        Customer customer = customerService.selectById(id);
        return customer;
    }

    /**
     * 本地服务实例的信息
     * @return
     */
    @GetMapping("/instance-info")
    public ServiceInstance showInfo() {
        ServiceInstance localServiceInstance = this.discoveryClient.getLocalServiceInstance();
        return localServiceInstance;
    }
}
